<?php

namespace app\admin\controller;

use app\admin\model\Member as MemberModel;
use app\common\model\MiningPledge as MiningPledgeModel;

class Pledge extends Admin
{
    function index(){
        if (!$this->request->isPost()){
            return view('index');
        }else {
            $limit = $this->request->post('limit', 20, 'intval');
            $page = $this->request->post('page', 1, 'intval');
            $type = $this->request->post('type', 1, 'intval');

            $where = [];
            if(!empty($type)) $where['mining_oneself'] = $type;

            $res = MiningPledgeModel::getList($limit,$page,$where);

            foreach ($res['data'] as $k => $v){
                $member = MemberModel::getDetails($v['mid']);
                $res['data'][$k]['username'] = !empty($member) ? $v['mid'].' | '.$member['username'] : $v['mid'];
            }

            $data['status'] = 200;
            $data['data'] = $res;
            return json($data);
        }
    }
}